package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.Area;
import cn.poco.pepsi.bean.HotSearchKey;

public class HotKeyXmlparse {
	//private final static String TAG = "DisAreaXmlparse";
	private static ArrayList<HotSearchKey> keys = null;
	private static  HotSearchKey keyBean = null;
	
	public static ArrayList<HotSearchKey> getXml(InputStream inSteam) throws Exception{
		XmlPullParser xmpparse = Xml.newPullParser();   //寰楀埌瑙ｉ噴鍣�
		xmpparse.setInput(inSteam, "UTF-8");           //璁剧疆瑙ｉ噴娴�
		int code = xmpparse.getEventType();            //寰楀埌鑺傜偣淇℃伅
		
		
		while(code!=XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				keys = new ArrayList<HotSearchKey>();
				break;
			case XmlPullParser.START_TAG:
				if("key".equals(xmpparse.getName())){
					keyBean = new HotSearchKey();
				}
				if(keyBean!=null){
					if("keyword".equals(xmpparse.getName())){
						String keyw = xmpparse.nextText();
						keyBean.setKeyword(keyw);
					}
					
				}
				break;
			case XmlPullParser.END_TAG:
				if("key".equals(xmpparse.getName())){
					keys.add(keyBean);
					System.out.println("keys----->size"+keys.size());
					keyBean = null;
				}
				break;
			}	
			
			try {
				code = xmpparse.next();
				System.out.println("code = xmpparse.next();正常");
			} catch (Exception e) {
				System.out.println("有异常");
				code=XmlPullParser.END_DOCUMENT;
			}
			
		}
	    inSteam.close();
		System.out.println("xmlparse---->keys.size"+keys.size());
		
		if(keys.size()==0){
			
			ArrayList<HotSearchKey> testlist=new ArrayList<HotSearchKey>();
			HotSearchKey testObj=new HotSearchKey();
			testObj.setKeyword("test");
			testlist.add(testObj);
			System.out.println("return testlist;");
			return testlist;
			
		}else{
			System.out.println("XML——————》return  keys;");
			return  keys;
		}
		
		
		
		
	}
}
